<?php //I.F. Nuevo: 2011-04-03; ramarin

if (!defined('MOODLE_INTERNAL')) {
    die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
} 

require_once('../../../config.php');
require_once($CFG->dirroot.'/lib/formslib.php');
require_once($CFG->dirroot.'/'.$CFG->admin.'/report/moosisca/managecourseslib.php');

class courseapprovation_form extends moodleform {
  // Define the form
  function definition () {
    global $CFG, $COURSE, $USER;
    
    $courseName = "";
    $state = "";
    $id = required_param('id', PARAM_INT); 
    
    $courses = get_pending_approvation_courses('mw.id, mw.courseid, c.fullname, mw.state', "mw.id = " . $id . " AND (mw.state='observations'  OR mw.state='evaluation')");
    
    if (!$courses) {
      error('Course ID was incorrect');
    }
    else{
      foreach($courses as $course){
        $courseName = format_string($course["fullname"]);
        $state = get_string('workFlowState.' . $course["state"], 'report_moosisca'); 
      }
    }
    
    $course        = $this->_customdata['course'];
   
    $mform =& $this->_form;
    $strrequired = get_string('required');
    
    // the upload manager is used directly in entry processing, moodleform::save_files() is not used yet
    $this->set_upload_manager(new upload_manager('attachment', true, false, $COURSE, false, 0, true, true, false)); 
    
    /// Add some extra hidden fields
    $mform->addElement('hidden', 'id');
    $mform->setType('id', PARAM_INT);
    $mform->setDefault('id', $id);
    
    $mform->addElement('static', 'staticcourse', get_string("course"), $courseName);
    $mform->addElement('static', 'staticstate', get_string("state", "report_moosisca"), $state);
    
    $mform->addElement('htmleditor', 'observations', get_string('observations', 'report_moosisca'), array('cols'=>50, 'rows'=>20));
    $mform->setType('observations', PARAM_RAW);
    $mform->addRule('observations', get_string('required'), 'required', null, 'client');

    $mform->addElement('file', 'attachment', get_string('attachment', 'report_moosisca'));
    
    $mform->addElement('checkbox', 'mailnow', get_string('sendmail', 'report_moosisca'));
  
    $buttonarray = array();
    $buttonarray[] = &$mform->createElement('submit', 'btnApprove', get_string('approveCourse', 'report_moosisca'), 'xx');
    $buttonarray[] = &$mform->createElement('submit', 'btnUnApprove', get_string('unApproveCourse', 'report_moosisca'), 'xx');
    $mform->addGroup($buttonarray, 'grpObservations', '', array(' '), false);
  }

  function validation($usernew, $files) {
      return NULL;
  }
}
?>
